Partial Class Admin_Brokers
  Inherits System.Web.UI.Page

    Private Sub SecurePage()
        Dim sec As New Secure

        sec.ParentPage = Me
        sec.AddDataGridColumn(Me.DataGrid, DataGrid.Columns.Count - 2, Secure.ControlTypes.DeleteType)
        sec.AddDataGridColumn(Me.DataGrid, DataGrid.Columns.Count - 3, Secure.ControlTypes.EditType)
        sec.SetPageAccess(Session("UserName"))
        sec = Nothing
    End Sub

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If DataGrid.Items.Count < 1 Then
      Dim zClass As New LookUp.General_Lookup
      zClass.LookUpCode = "BROKER"
      DataGrid.CurrentPageIndex = 0
      zClass.DataGridFill(DataGrid, Results_lbl)
    End If

    Dim Edit_Image As Image = CType(Me.Master.FindControl("A1"), Image)
    Edit_Image.ImageUrl = "~/images/redT.PNG"
    Dim Edit_Button As LinkButton = CType(Me.Master.FindControl("Brokers_btn"), LinkButton)
    Edit_Button.ForeColor = Drawing.Color.Black
    Dim Edit_Panel As Panel = CType(Me.Master.FindControl("Affiliates_Panel"), Panel)
    Edit_Panel.Visible = True

        SecurePage()
  End Sub

  Protected Sub DataGrid_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid.ItemCommand
    If e.CommandName = "Edit" Or e.CommandName = "View" Then
      Session("broker_cd") = e.Item.Cells(0).Text
      Session("broker_mode") = e.CommandName
      Response.Redirect("~/Admin/Add_Broker.aspx")

    ElseIf e.CommandName = "Delete" Then
      Dim zClass As New LookUp.General_Lookup
      zClass.LookUpCode = "BROKER"

      DataGrid.CurrentPageIndex = 0
      If zClass.OKtoDELETE(e.Item.Cells(0).Text) = True Then
        zClass.ExecQuery("DELETE FROM broker_mstr WHERE broker_cd='" & e.Item.Cells(0).Text & "'")

        zClass.DataGridFill(DataGrid, Results_lbl)

      End If

    ElseIf e.CommandName = "Providers" Then
      Session("broker_cd") = e.Item.Cells(0).Text
      Response.Redirect("~/Admin/Providers.aspx")

    End If
  End Sub

  Protected Sub Add_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Add_btn.Click
    Session("broker_mode") = "Add"
    Response.Redirect("~/Admin/Add_Broker.aspx")

  End Sub

  Protected Sub DataGrid_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid.PageIndexChanged
    DataGrid.CurrentPageIndex = e.NewPageIndex
    Dim zClass As New LookUp.General_Lookup
    zClass.LookUpCode = "BROKER"
    zClass.DataGridFill(DataGrid, Results_lbl)

  End Sub

End Class